package com.hzit.consumer.listener;

import com.hzit.common.constant.HzitCodeMessageTopicConstants;
import com.hzit.common.utils.SmsUtil;
import com.hzit.consumer.config.JmsProperties;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@RocketMQMessageListener(consumerGroup = "consumer-group",topic = HzitCodeMessageTopicConstants.TOPIC)
@Component
public class ConsumerListener implements RocketMQListener<Map> {

	@Autowired
	private JmsProperties jmsProperties;
	@Autowired
	private SmsUtil smsUtil;
	//1. 接受消息
	@Override
	public void onMessage(Map map) {
		System.out.println("jmsProperties = " + jmsProperties);
		//1.1 准备信息
		System.out.println("map = " + map);
		String accessKeyId = jmsProperties.getAccessKeyId();
		String accessKeySecret = jmsProperties.getAccessKeySecret();
		String signName = jmsProperties.getSignName();
		String templateCode = jmsProperties.getTemplateCode();
		String code = map.get("code").toString();
		String phone = map.get("phone").toString();

		//1.2 发送消息到阿里云
		smsUtil.sendMsg(accessKeyId,accessKeySecret,phone,signName,templateCode,code);

		System.out.println("消息发送成功！");
	}
}

